﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CPPEI.Net
{
    public abstract class BaseRequestHandler<TRequestData, TResponseData> : IRequestHandler
    {
        public NetPackage Handle(NetServerData serverData, NetClientProxy requestClient, NetPackage package)
        {
            TRequestData requestData = (TRequestData)Serializer.FromNetBuffer(package);

            TResponseData responseData = OnHandle(serverData, requestClient, package, requestData);

            NetPackage response = new NetPackage(package.Command, package.ReplyMode, 0, Serializer.ToBinary(responseData));
            return response;
        }

        protected abstract TResponseData OnHandle(NetServerData serverData, NetClientProxy requestClient, NetPackage request, TRequestData requestData);
    }
}
